home *** CD-ROM | disk | FTP | other *** search
- //***************************************************************************************
- // Shadows.hlsl by Frank Luna (C) 2015 All Rights Reserved.
- //***************************************************************************************
-
- // Include common HLSL code.
- #include "Common.hlsl"
-
- struct VertexIn
- {
- float3 PosL : POSITION;
- float2 TexC : TEXCOORD;
- #ifdef SKINNED
- float3 BoneWeights : WEIGHTS;
- uint4 BoneIndices : BONEINDICES;
- #endif
- };
-
- struct VertexOut
- {
- float4 PosH : SV_POSITION;
- float2 TexC : TEXCOORD;
- };
-
- VertexOut VS(VertexIn vin)
- {
- VertexOut vout = (VertexOut)0.0f;
-
- MaterialData matData = gMaterialData[gMaterialIndex];
-
- #ifdef SKINNED
- float weights[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
- weights[0] = vin.BoneWeights.x;
- weights[1] = vin.BoneWeights.y;
- weights[2] = vin.BoneWeights.z;
- weights[3] = 1.0f - weights[0] - weights[1] - weights[2];
-
- float3 posL = float3(0.0f, 0.0f, 0.0f);
- for(int i = 0; i < 4; ++i)
- {
- // Assume no nonuniform scaling when transforming normals, so
- // that we do not have to use the inverse-transpose.
-
- posL += weights[i] * mul(float4(vin.PosL, 1.0f), gBoneTransforms[vin.BoneIndices[i]]).xyz;
- }
-
- vin.PosL = posL;
- #endif
-
- // Transform to world space.
- float4 posW = mul(float4(vin.PosL, 1.0f), gWorld);
-
- // Transform to homogeneous clip space.
- vout.PosH = mul(posW, gViewProj);
-
- // Output vertex attributes for interpolation across triangle.
- float4 texC = mul(float4(vin.TexC, 0.0f, 1.0f), gTexTransform);
- vout.TexC = mul(texC, matData.MatTransform).xy;
-
- return vout;
- }
-
- // This is only used for alpha cut out geometry, so that shadows
- // show up correctly. Geometry that does not need to sample a
- // texture can use a NULL pixel shader for depth pass.
- void PS(VertexOut pin)
- {
- // Fetch the material data.
- MaterialData matData = gMaterialData[gMaterialIndex];
- float4 diffuseAlbedo = matData.DiffuseAlbedo;
- uint diffuseMapIndex = matData.DiffuseMapIndex;
-
- // Dynamically look up the texture in the array.
- diffuseAlbedo *= gTextureMaps[diffuseMapIndex].Sample(gsamAnisotropicWrap, pin.TexC);
-
- #ifdef ALPHA_TEST
- // Discard pixel if texture alpha < 0.1. We do this test as soon
- // as possible in the shader so that we can potentially exit the
- // shader early, thereby skipping the rest of the shader code.
- clip(diffuseAlbedo.a - 0.1f);
- #endif
- }
-
-
-